package code.part01_base;/*


/**
 * @author: ZJT
 * @Time: 2021/7/4
 * @Description: 循环
 */

import org.junit.jupiter.api.Test;

public class P06_For {

    //while循环样例
    @Test
    public void whileDemo() {
        int i = 1;
        while (i <= 100) {
            System.out.println("第" + i + "遍输出");
            i++;
        }
    }

    // do while
    @Test
    public void doWhileDemo() {
        int i = 1;
        do {
            System.out.println("第" + i + "遍输出");
            i++;
        } while (i <= 100);
    }

    @Test
    public void forDemo() {
        for (int i = 1; i <= 100; i++) {
            System.out.println("第" + i + "遍输出");
        }

        //100以内的偶数和
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                sum += i;
            }
        }
        System.out.println("100以内的偶数和是：" + sum);
    }

    @Test
    public void forBreak() {
        for (int i = 1; i <= 10; i++) {
            if (i == 8) {
                break;
            }
            System.out.println("第" + i + "遍输出");
        }
        System.out.println("********************");

        for (int i = 1; i <= 10; i++) {
            if (i == 8) {
                continue;
            }
            System.out.println("第" + i + "遍输出");
        }
        System.out.println("********************");

        for (int i = 1; i <= 10; i++) {
            if (i == 8) {
                return;
            }
            System.out.println("第" + i + "遍输出");
        }

    }

    /**
     * @author: ZJT
     * @Time: 2021/7/6
     * @Description: 递归函数
     * @param:
     * @return:
     * @throws:
     */
    public static int getNumber(int number) {
        if (number == 1 || number == 2) {
            return 1;
        } else {
            return getNumber(number-1) ;
        }
    }
}